(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "react", "maishu-wuzhui", "maishu-wuzhui-helper", "react-dom", "services/dataSources"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const React = require("react");
    const maishu_wuzhui_1 = require("maishu-wuzhui");
    const maishu_wuzhui_helper_1 = require("maishu-wuzhui-helper");
    const ReactDOM = require("react-dom");
    const dataSources_1 = require("services/dataSources");
    // export default function (page: chitu.Page) {
    //     let shopping = page.createService(ShoppingService);
    //     ReactDOM.render(<CouponListPage />, page.element);
    // }
    class CouponListPage extends React.Component {
        // private itemEditor: wz.GridViewItemPopupEditor;
        componentDidMount() {
            let self = this;
            let gridView = maishu_wuzhui_helper_1.createGridView({
                element: this.couponsTable,
                dataSource: dataSources_1.dataSources.coupon,
                columns: [
                    new maishu_wuzhui_1.BoundField({ dataField: 'Title', headerText: '名称' }),
                    // new ui.BoundField({ dataField: 'Title', headerText: '标题' }),
                    new maishu_wuzhui_1.CustomField({
                        createItemCell(dataItem) {
                            let cell = new maishu_wuzhui_1.GridViewDataCell({
                                render(value, element) {
                                    ReactDOM.render(React.createElement("div", null,
                                        React.createElement("span", null, value.ValidBegin.toLocaleDateString()),
                                        React.createElement("span", null, " \u81F3 "),
                                        React.createElement("span", null, value.ValidEnd.toLocaleDateString())), cell.element);
                                    // wuzhui.Control.getControlByElement(cell.element.parentElement);
                                }
                            });
                            return cell;
                        },
                        headerText: '有效期'
                    }),
                    new maishu_wuzhui_1.BoundField({
                        dataField: 'Discount', headerText: '折扣金额', dataFormatString: '￥{C2}',
                        itemStyle: { textAlign: 'right' }
                    }),
                    new maishu_wuzhui_1.BoundField({
                        dataField: 'Amount', headerText: '使用金额', dataFormatString: '￥{C2}',
                        itemStyle: { textAlign: 'right' }
                    }),
                    new maishu_wuzhui_1.CustomField({
                        headerStyle: { width: '100px' },
                        itemStyle: { textAlign: "center" },
                        headerText: "操作",
                        createItemCell(dataItem) {
                            let cell = new maishu_wuzhui_1.GridViewCell();
                            ReactDOM.render(React.createElement(React.Fragment, null,
                                React.createElement("button", { className: "btn btn-minier btn-info", onClick: () => self.props.app.redirect("coupon/coupon-edit", { id: dataItem.Id }) },
                                    React.createElement("i", { className: "icon-pencil" })),
                                React.createElement("button", { className: "btn btn-minier btn-danger", onClick: () => self.props.app.redirect("coupon/coupon-edit", { id: dataItem.Id }) },
                                    React.createElement("i", { className: "icon-pencil" }))), cell.element);
                            return cell;
                        }
                    })
                ]
            });
        }
        render() {
            return (React.createElement("div", null,
                React.createElement("div", { className: "tabbable" },
                    React.createElement("ul", { className: "nav nav-tabs" },
                        React.createElement("li", { className: "pull-left active" },
                            React.createElement("a", null, "\u5168\u90E8")),
                        React.createElement("li", { "data-bind": "visible:currentIndex()==0", className: "pull-right" },
                            React.createElement("button", { onClick: () => this.props.app.redirect("coupon/coupon-edit"), className: "btn btn-sm btn-primary", title: "\u70B9\u51FB\u6DFB\u52A0\u4F18\u60E0\u5238" },
                                React.createElement("i", { className: "icon-plus" }),
                                React.createElement("span", null, "\u6DFB\u52A0"))))),
                React.createElement("table", { ref: (o) => this.couponsTable = this.couponsTable || o })));
        }
    }
    exports.default = CouponListPage;
});
